package com.killer.catalina;

import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.List;

/**
 * Service具体实现类
 */
public class StandardService implements Service {

    /**
     * 服务的名称
     */
    private String name;

    /**
     * 一个Service可以配置多个Connector
     */
    private List<Connector> connectors;

    /**
     * 一个Service可以配置一个Engine
     */
    private Engine engine;

    public Engine getEngine() {
        return engine;
    }

    public void setEngine(Engine engine) {
        this.engine = engine;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Connector> getConnectors() {
        return connectors;
    }

    public void setConnectors(List<Connector> connectors) {
        this.connectors = connectors;
    }

    @Override
    public void start() {
        //启动Engine引擎
        if (engine != null) {
            engine.start();
        }
        //启动所有的Connector
        if (CollectionUtils.isNotEmpty(connectors)) {
            for (Connector connector : connectors) {
                connector.start();
            }
        }
    }
}
